package com.example.a2209_shop.utils

import android.content.Context
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.example.a2209_shop.R

object LoadImg {
    @BindingAdapter("img_src")
    @JvmStatic
    fun loadImg(imageView: ImageView,url:String?){
        if(url!=null){
            Glide.with(imageView.context)
                .load(url)
                .into(imageView)
        }
    }

    fun loadnormal(context: Context,url:String,imageView: ImageView){
        Glide.with(context)
            .load(url)
            //.transform(CenterCrop(),RoundedCorners(20))
            .error(R.drawable.ic_launcher_background)//网址错误时占位
            .placeholder(R.drawable.ic_launcher_background)//网络图片还未加载时展示
            .skipMemoryCache(true)//是否跳过缓存
            .thumbnail(0.1f)//缩略图
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .into(imageView)
    }
}